//
//  ViewController.m
//  PopSheet
//
//  Created by G2 on 2021/7/15.
//

#import "ViewController.h"
#import "PopSheet.h"
#import "Drawer.h"

@interface ViewController ()<UIScrollViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"点击这里" forState:UIControlStateNormal];
    [btn setTitle:@"关闭" forState:UIControlStateSelected];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    [btn addTarget:self action:@selector(tap:) forControlEvents:UIControlEventTouchUpInside];
    btn.frame = CGRectMake(100, 100, 100, 30);
    btn.backgroundColor = [UIColor colorWithWhite:0.3 alpha:1];
    btn.layer.cornerRadius = 3;
    
    [self.view addSubview:btn];
}

- (void)tap:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected){
        PopSheet *sheet = [[PopSheet alloc] init];
        sheet.tag = 1002;
        Drawer *drawer = [[Drawer alloc] initWithFrame:CGRectMake(0, 300, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 300)];
        
        sheet.content = drawer;
        
        [sheet showInView:self.view block:^(BOOL dismissed) {
            sender.selected = !dismissed;
        }];
    }else{
        PopSheet *sheet = (PopSheet *)[self.view viewWithTag:1002];
        [sheet dismiss];
    }
  
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    
}
@end
